package com.ossjk.qlh.tgb.service.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ossjk.qlh.tgb.entity.ActivityInfo;
import com.ossjk.qlh.tgb.entity.ActivityUser;
import com.ossjk.qlh.tgb.mapper.ActivityInfoMapper;
import com.ossjk.qlh.tgb.service.IActivityInfoService;
import com.ossjk.qlh.tgb.service.IActivityUserService;
import com.ossjk.qlh.tgb.vo.ActivityInfoVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Copyright  Sat Jan 22 21:51:38 CST 2022 QLH. Tech Ltd. All rights reserved.
 * 
 * @Package: com.ossjk.qlh.projects
 * @ClassName: ActivityInfoController
 * @Description: ActivityInfo-服务实现类
 * @author: chair
 * @date:  2022-01-22 21:51:39 
 */
@Service
public class ActivityInfoServiceImpl extends ServiceImpl<ActivityInfoMapper, ActivityInfo> implements IActivityInfoService {

    @Autowired
    private IActivityUserService iActivityUserService;

    @Override
    public Page getActivityInfoPage(Wrapper wrapper, Page page) {
        Page pageVo = this.baseMapper.getActivityInfoPage(wrapper,page);
        List<ActivityInfoVo> records = pageVo.getRecords();
        for (ActivityInfoVo record : records) {
            if (record.getStatus() == 1){
                record.setEnd(false);
            }else {
                record.setEnd(true);
            }
            //获取活动id
            String activityId = record.getId();
            //根据活动id查询付款人数
            QueryWrapper<ActivityUser> queryWrapper = new QueryWrapper<>();
            queryWrapper.eq("activity_id",activityId);
            queryWrapper.eq("is_payment",1);
            int count = iActivityUserService.count(queryWrapper);
            record.setSendCount(count);
        }
        return page;
    }
}
